#include "creatcharts.h"
#include <QPainter>
#include "qmath.h"
#include "QValueAxis"
#include "QBarCategoryAxis"

CreatCharts::CreatCharts()
{
    pc_good=new QColor(0x14,0x91,0xF7);
    pc_normal=new QColor(0x32,0x4A,0xD8);
    pc_bad=new QColor(0xC4,0x91,0x44);


}
CreatCharts::~CreatCharts()
{
    delete pc_good;
    delete pc_bad;
    delete pc_normal;


}
QChart *CreatCharts::createLineChart_HR()
{
    QChart *chart = new QChart();
    series_HR = new QLineSeries;
    QColor(0x96,0x88,0xFF);
    series_HR->setPen(QPen(QColor(00,0xDF,0xF5),5));
    chart->addSeries(series_HR);
    chart->createDefaultAxes();
    chart->setBackgroundVisible(true);
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));
    chart->axisY()->setRange(50, 120);
    chart->axisX()->setRange(0, Axes_HR_Len);

    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleText("次/分钟");
    chart->axisY()->setTitleBrush(QBrush(QColor(255, 255, 255),Qt::SolidPattern));
    chart->axisY()->setLabelsColor(QColor(255, 255, 255,255));
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisX()->setLineVisible(false);
    chart->legend()->hide(); /* hide legend */
    chart->axisX()->setVisible(false);
    chart->axisY()->setVisible(true);
    return chart;
}
/**
 * @brief CreatCharts::updateData
 * 功能：更新HR图表，绘图
 */
void CreatCharts::update_HRData(double hr)
{
    QVector<QPointF> oldData = series_HR->pointsVector();
    QVector<QPointF> data;
    if (oldData.size() < Axes_HR_Len) {
        data = series_HR->pointsVector();
    } else {
        for (int i = 1; i < oldData.size(); ++i) {
            data.append(QPointF(i - 1 , oldData.at(i).y()));
        }
    }
    qint64 size = data.size();
    data.append(QPointF(size, hr));
    series_HR->replace(data);
}
QChart *CreatCharts::createLineChart_OX()
{
    QChart *chart = new QChart();
    series_Ox = new QLineSeries;
    series_Ox->setPen(QPen(QColor(00,0xDF,0xF5),5));
//    for(int i=0;i<Axes_OX_Len;i++)
//      series_Ox->append(i,0);
    chart->addSeries(series_Ox);
    chart->createDefaultAxes();
    chart->setBackgroundVisible(true);
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));
    chart->axisY()->setRange(90, 100);
    chart->axisX()->setRange(0, Axes_OX_Len);

    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));//X轴标尺名字字体
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));//标尺数字字体
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleText("SPOx%");
    chart->axisY()->setTitleBrush(QBrush(QColor(255, 255, 255),Qt::SolidPattern));
    chart->axisY()->setLabelsColor(QColor(255, 255, 255,255));
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisX()->setLineVisible(false);
    chart->legend()->hide(); /* hide legend */
    chart->axisX()->setVisible(false);
    chart->axisY()->setVisible(true);
    return chart;
}
/**
 * @brief CreatCharts::updateData
 * 功能：更新OX图表，绘图
 */
void CreatCharts::update_OXData(double ox)
{
    QVector<QPointF> oldData = series_Ox->pointsVector();
    QVector<QPointF> data;
    if (oldData.size() < Axes_OX_Len) {
        data = series_Ox->pointsVector();
    } else {
        for (int i = 1; i < oldData.size(); ++i) {
            data.append(QPointF(i - 1 , oldData.at(i).y()));
        }
    }
    qint64 size = data.size();
    data.append(QPointF(size, ox));
    series_Ox->replace(data);
}

QChart *CreatCharts::createLineChart_MP()
{
    QChart *chart = new QChart();
    series_Mp = new QLineSeries;
    series_Mp->setPen(QPen(QColor(00,0xDF,0xF5),5));
    chart->addSeries(series_Mp);
    chart->createDefaultAxes();
    chart->setBackgroundVisible(true);
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));
    chart->axisY()->setRange(0, 100);
    chart->axisX()->setRange(0, Axes_MP_Len);
    // Add space to label to add space between labels and axis
    QValueAxis *axisY = qobject_cast<QValueAxis*>(chart->axes(Qt::Vertical).first());
    Q_ASSERT(axisY);
    axisY->setLabelFormat("%.1f  ");

    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));//X轴标尺名字字体
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));//标尺数字字体
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleText("压力");
    chart->axisY()->setTitleBrush(QBrush(QColor(255, 255, 255),Qt::SolidPattern));
    chart->axisY()->setLabelsColor(QColor(255, 255, 255,255));
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisX()->setLineVisible(false);
    chart->legend()->hide(); /* hide legend */
    chart->axisX()->setVisible(false);
    chart->axisY()->setVisible(true);
    return chart;
}
/**
 * @brief CreatCharts::updateData
 * 功能：更新MP图表，绘图
 */
void CreatCharts::update_MPData(double mp)
{
    QVector<QPointF> oldData = series_Mp->pointsVector();
    QVector<QPointF> data;
    if (oldData.size() < Axes_MP_Len) {
        data = series_Mp->pointsVector();
    } else {
        for (int i = 1; i < oldData.size(); ++i) {
            data.append(QPointF(i - 1 , oldData.at(i).y()));
        }
    }
    qint64 size = data.size();
    data.append(QPointF(size, mp));
    series_Mp->replace(data);
}
QChart *CreatCharts::createPieChart_MP()
{
    QChart *chart = new QChart();
    chart->setTitle("压力分布");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    Pieseries_MP = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("压力小",30);
    QPieSlice *slice2 = new QPieSlice("压力正常",30);
    QPieSlice *slice3 = new QPieSlice("压力大",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_mp.append(slice1);
    slices_mp.append(slice2);
    slices_mp.append(slice3);

    Pieseries_MP->append(slices_mp);
    Pieseries_MP->setPieSize(0.8);
    chart->addSeries(Pieseries_MP);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}

/**
 * @brief CreatCharts::update_MP_PieData
 * 功能：更新MP 圆饼图表，绘图
 */
void CreatCharts::update_MP_PieData(QList<double>mp)
{
    int Len=mp.size();
    int v_1=0;
    int v_2=0;
    int v_3=0;
    if(Len>2)
    {
       for(int i=0;i<Len;i++)
       {
           if(mp.at(i)<30)
               v_1++;
           else if(mp.at(i)>70)
               v_3++;
           else
               v_2++;
       }
    }
    qreal mp1=v_1*100.0/Len;
    qreal mp2=v_2*100.0/Len;
    qreal mp3=100.0-(mp1+mp2);
    slices_mp.at(0)->setValue(mp1);
    slices_mp.at(1)->setValue(mp2);
    slices_mp.at(2)->setValue(mp3);
}

QChart *CreatCharts::createPieChart_PSD()
{
    QChart *chart = new QChart();
    chart->setTitle("功率谱密度分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    PieSeries_PSD = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("VLF",30);
    QPieSlice *slice2 = new QPieSlice("LF",30);
    QPieSlice *slice3 = new QPieSlice("HF",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_psd.append(slice1);
    slices_psd.append(slice2);
    slices_psd.append(slice3);

    PieSeries_PSD->append(slices_psd);
    PieSeries_PSD->setPieSize(0.8);
    chart->addSeries(PieSeries_PSD);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}
/**
 * @brief CreatCharts::createPieChart_a_hr
 * @return
 */
QChart *CreatCharts::createPieChart_a_hr()
{
    QChart *chart = new QChart();
    chart->setTitle("心率分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("偏小",30);
    QPieSlice *slice2 = new QPieSlice("正常",30);
    QPieSlice *slice3 = new QPieSlice("偏大",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_HR.append(slice1);
    slices_A_HR.append(slice2);
    slices_A_HR.append(slice3);

    PieSeries->append(slices_A_HR);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}



/**
 * @brief CreatCharts::createPieChart_a_ox
 * @return
 */
QChart *CreatCharts::createPieChart_a_ox()
{
    QChart *chart = new QChart();
    chart->setTitle("血氧分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("极度偏小",30);
    QPieSlice *slice2 = new QPieSlice("偏小",30);
    QPieSlice *slice3 = new QPieSlice("正常",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_OX.append(slice1);
    slices_A_OX.append(slice2);
    slices_A_OX.append(slice3);

    PieSeries->append(slices_A_OX);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}
/**
 * @brief CreatCharts::createPieChart_a_mp
 * @return
 */
QChart *CreatCharts::createPieChart_a_mp()
{
    QChart *chart = new QChart();
    chart->setTitle("压力分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("压力小",30);
    QPieSlice *slice2 = new QPieSlice("压力正常",30);
    QPieSlice *slice3 = new QPieSlice("压力大",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_MP.append(slice1);
    slices_A_MP.append(slice2);
    slices_A_MP.append(slice3);

    PieSeries->append(slices_A_MP);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}

/**
 * @brief CreatCharts::createPieChart_a_fatigure
 * @return
 */
QChart *CreatCharts::createPieChart_a_fatigure()
{
    QChart *chart = new QChart();
    chart->setTitle("疲劳指数分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("疲劳度小",30);
    QPieSlice *slice2 = new QPieSlice("疲劳度正常",30);
    QPieSlice *slice3 = new QPieSlice("疲劳度大",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_FATIGURE.append(slice1);
    slices_A_FATIGURE.append(slice2);
    slices_A_FATIGURE.append(slice3);

    PieSeries->append(slices_A_FATIGURE);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}

/**
 * @brief CreatCharts::createPieChart_a_depress
 * @return
 */
QChart *CreatCharts::createPieChart_a_depress()
{
    QChart *chart = new QChart();
    chart->setTitle("情绪消极分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("无消极",30);
    QPieSlice *slice2 = new QPieSlice("消极正常",30);
    QPieSlice *slice3 = new QPieSlice("消极",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_DEPRESS.append(slice1);
    slices_A_DEPRESS.append(slice2);
    slices_A_DEPRESS.append(slice3);

    PieSeries->append(slices_A_DEPRESS);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}


/**
 * @brief CreatCharts::createPieChart_a_ansiety
 * @return
 */
QChart *CreatCharts::createPieChart_a_ansiety()
{
    QChart *chart = new QChart();
    chart->setTitle("情绪焦虑分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("无焦虑",30);
    QPieSlice *slice2 = new QPieSlice("焦虑正常",30);
    QPieSlice *slice3 = new QPieSlice("焦虑",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slices_A_ANSIETY.append(slice1);
    slices_A_ANSIETY.append(slice2);
    slices_A_ANSIETY.append(slice3);

    PieSeries->append(slices_A_ANSIETY);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}

/**
 * @brief CreatCharts::createPieChart_a_ballance
 * @return
 */
QChart *CreatCharts::createPieChart_a_ballance()
{
    QChart *chart = new QChart();
    chart->setTitle("自主神经系统平衡性分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("差",30);
    QPieSlice *slice2 = new QPieSlice("正常",30);
    QPieSlice *slice3 = new QPieSlice("好",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slices_A_BALLANCE.append(slice1);
    slices_A_BALLANCE.append(slice2);
    slices_A_BALLANCE.append(slice3);

    PieSeries->append(slices_A_BALLANCE);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}

/**
 * @brief CreatCharts::createPieChart_a_activity
 * @return
 */
QChart *CreatCharts::createPieChart_a_activity()
{
    QChart *chart = new QChart();
    chart->setTitle("自主神经系统活性分布图");
    chart->setTitleBrush(QBrush(QColor(255,255,255)));
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setAnimationOptions(QChart::SeriesAnimations);//设置动画
    QPieSeries *PieSeries = new QPieSeries();
    QPieSlice *slice1 = new QPieSlice("差",30);
    QPieSlice *slice2 = new QPieSlice("正常",30);
    QPieSlice *slice3 = new QPieSlice("好",40);
    slice1->setLabelVisible();
    slice2->setLabelVisible();
    slice3->setLabelVisible();
    slice1->setBrush(QBrush(*pc_bad,Qt::SolidPattern));
    slice2->setBrush(QBrush(*pc_normal,Qt::SolidPattern));
    slice3->setBrush(QBrush(*pc_good,Qt::SolidPattern));
    slices_A_ACTIVITY.append(slice1);
    slices_A_ACTIVITY.append(slice2);
    slices_A_ACTIVITY.append(slice3);

    PieSeries->append(slices_A_ACTIVITY);
    PieSeries->setPieSize(0.8);
    chart->addSeries(PieSeries);
    chart->legend()->show();
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setFont(QFont("微软雅黑", 12, QFont::Normal, true));
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));

    return chart;
}
/**
 * @brief CreatCharts::update_MP_PieData
 * 功能：更新MP 圆饼图表，绘图
 */
void CreatCharts::update_A_PieData(int type,QList<int>v)
{
    int v1=v.at(0);
    int v2=v.at(1);
    int v3=v.at(2);
    double sum=v1+v2+v3;
    if(sum!=0){
        qreal mp1=v1*100.0/sum;
        qreal mp2=v2*100.0/sum;
        qreal mp3=100.0-(mp1+mp2);
        switch (type) {
        case 0:
            slices_A_HR.at(0)->setValue(mp1);
            slices_A_HR.at(1)->setValue(mp2);
            slices_A_HR.at(2)->setValue(mp3);
            break;
        case 1:
            slices_A_OX.at(0)->setValue(mp1);
            slices_A_OX.at(1)->setValue(mp2);
            slices_A_OX.at(2)->setValue(mp3);
            break;

        case 2:
            slices_A_MP.at(0)->setValue(mp1);
            slices_A_MP.at(1)->setValue(mp2);
            slices_A_MP.at(2)->setValue(mp3);
            break;
        case 3:
            slices_A_FATIGURE.at(0)->setValue(mp1);
            slices_A_FATIGURE.at(1)->setValue(mp2);
            slices_A_FATIGURE.at(2)->setValue(mp3);
            break;
        case 4:
            slices_A_DEPRESS.at(0)->setValue(mp1);
            slices_A_DEPRESS.at(1)->setValue(mp2);
            slices_A_DEPRESS.at(2)->setValue(mp3);
            break;
        case 5:
            slices_A_ANSIETY.at(0)->setValue(mp1);
            slices_A_ANSIETY.at(1)->setValue(mp2);
            slices_A_ANSIETY.at(2)->setValue(mp3);
            break;
        case 6:
            slices_A_BALLANCE.at(0)->setValue(mp1);
            slices_A_BALLANCE.at(1)->setValue(mp2);
            slices_A_BALLANCE.at(2)->setValue(mp3);
            break;
        case 7:
            slices_A_ACTIVITY.at(0)->setValue(mp1);
            slices_A_ACTIVITY.at(1)->setValue(mp2);
            slices_A_ACTIVITY.at(2)->setValue(mp3);
            break;
        }

    }
}
/**
 * @brief CreatCharts::update_MP_PieData
 * 功能：更新MP 圆饼图表，绘图
 */
void CreatCharts::update_PSD_PieData(double vlf,double lf,double hf)
{
    double sum=vlf+lf+hf;
    if(sum!=0){
        qreal mp1=vlf*100.0/sum;
        qreal mp2=lf*100.0/sum;
        qreal mp3=100.0-(mp1+mp2);
        slices_psd.at(0)->setValue(mp1);
        slices_psd.at(1)->setValue(mp2);
        slices_psd.at(2)->setValue(mp3);
    }
}


QChart *CreatCharts::createHRVHistBarChart()
{
    HRVHist_BarSet = new QBarSet("HRV_Hist");
    HRVHist_BarSet->setColor(QColor(15, 129, 248));

    QBarSeries *HRV_Barseries = new QBarSeries();
    for(int i=0;i<20;i++){
        HRVHist_BarSet->append(0);
    }
    HRV_Barseries->append(HRVHist_BarSet);
    QChart *HRV_Barchart = new QChart();
    HRV_Barchart->addSeries(HRV_Barseries);
    HRV_Barchart->setTitle("");

    HRV_Barchart->setAnimationOptions(QChart::SeriesAnimations);
    QBarCategoryAxis *axis = new QBarCategoryAxis();
//    axis->append(categories);

    HRV_Barchart->createDefaultAxes();
    HRV_Barchart->setAxisX(axis, HRV_Barseries);
    HRV_Barchart->legend()->setVisible(false);
    HRV_Barchart->legend()->setAlignment(Qt::AlignBottom);

    HRV_Barchart->setBackgroundVisible(false);
    HRV_Barchart->axisX()->setGridLineVisible(false);
    HRV_Barchart->axisX()->setVisible(false);
    HRV_Barchart->axisX()->setRange(0,20);
    HRV_Barchart->axisX()->setTitleText("毫秒");
    HRV_Barchart->axisX()->setLabelsColor(QColor(255,255,255));
    HRV_Barchart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    HRV_Barchart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));

    HRV_Barchart->axisY()->setGridLineVisible(true);
    HRV_Barchart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    HRV_Barchart->axisY()->setTitleText("个数");
    HRV_Barchart->axisY()->setLabelsColor(QColor(255,255,255));
    HRV_Barchart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    HRV_Barchart->axisY()->setVisible(true);
    HRV_Barchart->axisY()->setTitleBrush(QColor(255,255,255));//设置x轴字体颜色
    HRV_Barchart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    HRV_Barchart->axisY()->setRange(0,100);
    HRV_Barchart->setTitle("直方图");
    HRV_Barchart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    HRV_Barchart->setTitleBrush(QColor(255,255,255));
    return HRV_Barchart;
}
void CreatCharts::update_HRVHistBarData(QList<int>RR,int RR_len)
{
    int nums[20]={0};
    for(int i=0;i<RR_len;i++){
        int c_rr=RR.at(i);
        if(c_rr<500)
            nums[0]=nums[0]+1;
        if(c_rr>=500 && c_rr<535)
            nums[1]=nums[1]+1;
        if(c_rr>=535 && c_rr<570)
            nums[2]=nums[2]+1;
        if(c_rr>=570 && c_rr<605)
            nums[3]=nums[3]+1;
        if(c_rr>=605 && c_rr<640)
            nums[4]=nums[4]+1;
        if(c_rr>=640 && c_rr<675)
            nums[5]=nums[5]+1;
        if(c_rr>=675 && c_rr<710)
            nums[6]=nums[6]+1;
        if(c_rr>=710 && c_rr<745)
            nums[7]=nums[7]+1;
        if(c_rr>=745 && c_rr<780)
            nums[8]=nums[8]+1;
        if(c_rr>=780 && c_rr<815)
            nums[9]=nums[9]+1;
        if(c_rr>=815 && c_rr<850)
            nums[10]=nums[10]+1;
        if(c_rr>=885 && c_rr<920)
            nums[11]=nums[11]+1;
        if(c_rr>=920 && c_rr<955)
            nums[12]=nums[12]+1;
        if(c_rr>=955 && c_rr<990)
            nums[13]=nums[13]+1;
        if(c_rr>=990 && c_rr<1025)
            nums[14]=nums[14]+1;
        if(c_rr>=1025 && c_rr<1060)
            nums[15]=nums[15]+1;
        if(c_rr>=1060 && c_rr<1095)
            nums[16]=nums[16]+1;
        if(c_rr>=1095 && c_rr<1130)
            nums[17]=nums[17]+1;
        if(c_rr>=1130 && c_rr<1165)
            nums[18]=nums[18]+1;
        if(c_rr>=1165 )
            nums[19]=nums[19]+1;
    }
    for(int i=0;i<20;i++){
        HRVHist_BarSet->replace(i,nums[i]);
    }
}


QChart * CreatCharts::createAreaChart()
{
    QChart *chart = new QChart();
    lowerSeries_vlf = new QLineSeries(chart);
    upperSeries_vlf = new QLineSeries(chart);
    for(int i=0;i<47;i++)
    {
        lowerSeries_vlf->append(QPoint(i,0));
        upperSeries_vlf->append(QPoint(i,0));
    }
    lowerSeries_lf = new QLineSeries(chart);
    upperSeries_lf = new QLineSeries(chart);
    for(int i=47;i<175;i++)
    {
        lowerSeries_lf->append(QPoint(i,0));
        upperSeries_lf->append(QPoint(i,0));
    }
    lowerSeries_hf = new QLineSeries(chart);
    upperSeries_hf = new QLineSeries(chart);
    for(int i=175;i<465;i++)
    {
        lowerSeries_hf->append(QPoint(i,0));
        upperSeries_hf->append(QPoint(i,0));
    }
    area_VLF = new QAreaSeries(upperSeries_vlf, lowerSeries_vlf);
    area_LF = new QAreaSeries(upperSeries_lf, lowerSeries_lf);
    area_HF = new QAreaSeries(upperSeries_hf, lowerSeries_hf);

    area_VLF->setBrush(QBrush(QColor(156, 82, 225),Qt::SolidPattern));
    area_LF->setBrush(QBrush(QColor(0xFB,0xB8,0x15),Qt::SolidPattern));
    area_HF->setBrush(QBrush(QColor(00,0xDF,0xF5),Qt::SolidPattern));


    chart->addSeries(area_VLF);
    chart->addSeries(area_LF);
    chart->addSeries(area_HF);

    chart->createDefaultAxes();
    chart->legend()->setVisible(false);
    chart->setBackgroundVisible(false);
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(false);
    chart->axisX()->setTitleBrush(QColor(255,255,255));//设置x轴字体颜色
    chart->axisY()->setTitleBrush(QColor(255,255,255));//设置y轴字体颜色
    chart->axisY()->setTitleText("功率谱密度");
    chart->axisY()->setRange(0,10000);
    chart->axisX()->setTitleText("频率");
    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));//X轴标尺名字字体
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));//标尺数字字体
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setLabelsColor(QColor(255,255,255));
    chart->axisX()->setLabelsColor(QColor(255,255,255));
    chart->setTitle("功率谱图");
    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    chart->setTitleBrush(QColor(255,255,255));

    return chart;
}
void CreatCharts::update_HRVAreaData(QList<double> freq,QList<double> psd)
{
    for(int i=0;i<47;i++)
    {
        lowerSeries_vlf->replace(lowerSeries_vlf->at(i).x(),lowerSeries_vlf->at(i).y(),freq[i],psd[i]);
        upperSeries_vlf->replace(upperSeries_vlf->at(i).x(),upperSeries_vlf->at(i).y(),freq[i],psd[i]);
    }
    for(int i=47;i<175;i++)
    {
        lowerSeries_lf->replace(lowerSeries_lf->at(i).x(),lowerSeries_lf->at(i).y(),freq[i],psd[i]);
        upperSeries_lf->replace(upperSeries_lf->at(i).x(),upperSeries_lf->at(i).y(),freq[i],psd[i]);
    }
    for(int i=175;i<465;i++){
        lowerSeries_hf->replace(lowerSeries_hf->at(i).x(),lowerSeries_hf->at(i).y(),freq[i],psd[i]);
        upperSeries_hf->replace(upperSeries_hf->at(i).x(),upperSeries_hf->at(i).y(),freq[i],psd[i]);
    }
    area_VLF->setUpperSeries(upperSeries_vlf);
    area_LF->setUpperSeries(upperSeries_lf);
    area_HF->setUpperSeries(upperSeries_hf);

}
QChart* CreatCharts::creatScatterchart()
{
    QScatterSeries *series0 = new QScatterSeries();
    series0->setName("line");
    series0->setMarkerShape(QScatterSeries::MarkerShapeRectangle);
    series0->setMarkerSize(1.0);
//    series0->setColor(QColor::black());
    HRV_Scatterseries = new QScatterSeries();
    HRV_Scatterseries->setName("hrv_scatter");
//    HRV_Scatterseries->setMarkerShape(QScatterSeries::MarkerShapeCircle);
    HRV_Scatterseries->setMarkerSize(12.0);
//    HRV_Scatterseries->setColor(QColor::blue());
    for(int i=0;i<1500;i++){
       series0->append(i, i);
    }
    QChart *HRV_Scatterchart=new QChart;
    HRV_Scatterchart->addSeries(series0);


    HRV_Scatterchart->addSeries(HRV_Scatterseries);

    HRV_Scatterchart->setTitle("");

    HRV_Scatterchart->createDefaultAxes();
    HRV_Scatterchart->axisX()->setGridLineVisible(false);
    HRV_Scatterchart->axisY()->setGridLineVisible(false);
    HRV_Scatterchart->legend()->setVisible(false);
    HRV_Scatterchart->setBackgroundVisible(false);
    HRV_Scatterchart->axisX()->setVisible(true);
    HRV_Scatterchart->axisY()->setRange(0,1500);
    HRV_Scatterchart->axisY()->setTitleText("毫秒");
    HRV_Scatterchart->axisX()->setTitleText("毫秒");
//    HRV_Scatterchart->setTitleBrush(QColor(255,255,255));  //设置标题颜色
    HRV_Scatterchart->axisX()->setTitleBrush(QColor(255,255,255));//设置x轴字体颜色
    HRV_Scatterchart->axisY()->setTitleBrush(QColor(255,255,255));//设置x轴字体颜色
    HRV_Scatterchart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    HRV_Scatterchart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));//X轴标尺名字字体
    HRV_Scatterchart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));//标尺数字字体
    HRV_Scatterchart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    HRV_Scatterchart->axisY()->setLabelsColor(QColor(255,255,255));
    HRV_Scatterchart->axisX()->setLabelsColor(QColor(255,255,255));
    HRV_Scatterchart->axisX()->setRange(0,1500);
    HRV_Scatterchart->axisY()->setVisible(true);
    HRV_Scatterchart->setTitle("散点图");
    HRV_Scatterchart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    HRV_Scatterchart->setTitleBrush(QColor(255,255,255));
    return  HRV_Scatterchart;
}

void CreatCharts::update_HRVScatterData(QList<int> RR,int RR_Len)
{
    HRV_Scatterseries->clear();
    if(RR_Len>2)
    {
        for(int i=0;i<RR_Len-1;i++){
            if(RR[i]>0)
                HRV_Scatterseries->append(QPoint(RR[i],RR[i+1]));
        }
    }
}
QChart* CreatCharts::DrawHRV_BallanceBarChart()
{
    HRV_BallanceBarSet = new QBarSet("HRV_Ballance");
    HRV_BallanceBarSet->append(0);
    HRV_BallanceBarSet->append(0);
    QStringList categories;
    categories.append("迷走神经");
    categories.append("交感神经");
    QBarSeries *HRV_BallanceBarseries = new QBarSeries();
    HRV_BallanceBarseries->append(HRV_BallanceBarSet);
    QChart *HRV_BallanceBarchart = new QChart();
    HRV_BallanceBarchart->addSeries(HRV_BallanceBarseries);
    HRV_BallanceBarchart->setTitle("");

    HRV_BallanceBarchart->setAnimationOptions(QChart::SeriesAnimations);
    QBarCategoryAxis *axis = new QBarCategoryAxis();
    axis->append(categories);
    HRV_BallanceBarchart->createDefaultAxes();
    HRV_BallanceBarchart->setAxisX(axis, HRV_BallanceBarseries);
    HRV_BallanceBarchart->legend()->setVisible(false);
    HRV_BallanceBarchart->legend()->setAlignment(Qt::AlignBottom);
    HRV_BallanceBarchart->setBackgroundVisible(false);
    HRV_BallanceBarchart->axisX()->setVisible(true);
    HRV_BallanceBarchart->axisY()->setRange(0,100);
    HRV_BallanceBarchart->axisY()->setVisible(true);
    HRV_BallanceBarchart->axisY()->setLabelsColor(QColor(255,255,255));
    HRV_BallanceBarchart->axisX()->setLabelsColor(QColor(255,255,255));

    HRV_BallanceBarchart->setTitle("自主神经系统平衡图");
    HRV_BallanceBarchart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
    HRV_BallanceBarchart->setTitleBrush(QColor(255,255,255));
    HRV_BallanceBarchart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    return HRV_BallanceBarchart;
}
void CreatCharts::update_BallanceData(int SNE)
{
    HRV_BallanceBarSet->replace(0,100-SNE);
    HRV_BallanceBarSet->replace(1,SNE);
}
QChart *CreatCharts::createLineChart_Battle_Lines()
{
    QChart *chart = new QChart();
    chart->setTitle("身心健康趋势图");
    QFont font_Header;
    font_Header.setPixelSize(20);
    font_Header.setFamily("宋体");
    font_Header.setBold(true);
    chart->setTitleFont(font_Header);
    chart->setTitleBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));

    series_A = new QLineSeries;
    series_A->setName("A组");
    series_A->setPen(QPen(QColor(00,0xDF,0xF5),5));

    series_B = new QLineSeries;
    series_B->setName("B组");
    series_B->setPen(QPen(QColor(0xEE,0x44,0xF5),5));

    series_C = new QLineSeries;
    series_C->setName("C组");
    series_C->setPen(QPen(QColor(0xD3,0xDF,0x33),5));

    series_D = new QLineSeries;
    series_D->setName("D组");
    series_D->setPen(QPen(QColor(0x33,0xA3,0x35),5));

    chart->addSeries(series_A);
    chart->addSeries(series_B);
    chart->addSeries(series_C);
    chart->addSeries(series_D);

    chart->createDefaultAxes();
    chart->setBackgroundVisible(true);
    chart->setBackgroundBrush(QBrush(QColor(0,0,0,0)));
    chart->axisY()->setRange(5, 100);
    chart->axisX()->setRange(0, Axes_OX_Len);

    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));//X轴标尺名字字体
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));//标尺数字字体
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setTitleText("");
    chart->axisY()->setTitleBrush(QBrush(QColor(255, 255, 255),Qt::SolidPattern));
    chart->axisY()->setLabelsColor(QColor(255, 255, 255,255));
    chart->axisX()->setGridLineVisible(false);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisX()->setLineVisible(false);
    chart->legend()->hide(); /* hide legend */
    chart->axisX()->setVisible(false);
    chart->axisY()->setVisible(true);
    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->legend()->setFont(QFont("微软雅黑",12,true));
    return chart;
}

void CreatCharts::update_LineChart_Battle_LinesData(double data_a, double data_b, double data_c, double data_d)
{
    QVector<QPointF> oldData_A = series_A->pointsVector();
    QVector<QPointF> data_A;
    if (oldData_A.size() < Axes_OX_Len) {
        data_A = series_A->pointsVector();
    } else {
        for (int i = 1; i < oldData_A.size(); ++i) {
            data_A.append(QPointF(i - 1 , oldData_A.at(i).y()));
        }
    }
    qint64 size_A = data_A.size();
    data_A.append(QPointF(size_A, data_a));
    series_A->replace(data_A);


    QVector<QPointF> oldData_B = series_B->pointsVector();
    QVector<QPointF> data_B;
    if (oldData_B.size() < Axes_OX_Len) {
        data_B = series_B->pointsVector();
    } else {
        for (int i = 1; i < oldData_B.size(); ++i) {
            data_B.append(QPointF(i - 1 , oldData_B.at(i).y()));
        }
    }
    qint64 size_B = data_B.size();
    data_B.append(QPointF(size_B, data_b));
    series_B->replace(data_B);


    QVector<QPointF> oldData_C = series_C->pointsVector();
    QVector<QPointF> data_C;
    if (oldData_C.size() < Axes_OX_Len) {
        data_C = series_C->pointsVector();
    } else {
        for (int i = 1; i < oldData_C.size(); ++i) {
            data_C.append(QPointF(i - 1 , oldData_C.at(i).y()));
        }
    }
    qint64 size_C = data_C.size();
    data_C.append(QPointF(size_C, data_c));
    series_C->replace(data_C);


    QVector<QPointF> oldData_D = series_D->pointsVector();
    QVector<QPointF> data_D;
    if (oldData_C.size() < Axes_OX_Len) {
        data_D = series_D->pointsVector();
    } else {
        for (int i = 1; i < oldData_D.size(); ++i) {
            data_D.append(QPointF(i - 1 , oldData_D.at(i).y()));
        }
    }
    qint64 size_D = data_D.size();
    data_D.append(QPointF(size_D, data_d));
    series_D->replace(data_D);
}

QChart *CreatCharts::createABCDHistBarChart()
{
    QChart *chart = new QChart();
    chart->setTitle("身心健康指数");
    QFont font_Header;
    font_Header.setPixelSize(20);
    font_Header.setFamily("宋体");
    font_Header.setBold(true);
    chart->setTitleFont(font_Header);
    chart->setTitleBrush(QBrush(QColor(220,220,220),Qt::SolidPattern));


    QStackedBarSeries *series = new QStackedBarSeries(chart);
    AHist_BarSet = new QBarSet("A组");
    BHist_BarSet = new QBarSet("B组");
    CHist_BarSet = new QBarSet("C组");
    DHist_BarSet = new QBarSet("D组");
    for(int i(0);i<4;i++)
    {
        *AHist_BarSet << 0;
        *BHist_BarSet << 0;
        *CHist_BarSet << 0;
        *DHist_BarSet << 0;
    }
    AHist_BarSet->setColor(QColor(00,0xDF,0xF5));
    BHist_BarSet->setColor(QColor(0xEE,0x44,0xF5));
    CHist_BarSet->setColor(QColor(0xD3,0xDF,0x33));
    DHist_BarSet->setColor(QColor(0x33,0xA3,0x35));
    series->setLabelsPosition(QAbstractBarSeries::LabelsOutsideEnd);

    series->append(AHist_BarSet);
    series->append(BHist_BarSet);
    series->append(CHist_BarSet);
    series->append(DHist_BarSet);
    chart->addSeries(series);
    series->setLabelsPosition(QAbstractBarSeries::LabelsCenter);
    series->setLabelsVisible(true);
//    series->setLabelsPosition(QAbstractBarSeries::LabelsInsideEnd); // 设置数据系列标签的位置于数据柱内测上方
//    series->setLabelsVisible(true); // 设置显示数据系列标签
//    QValueAxis *m_ptrAxisX;
    QStringList categories;
    categories << "A组" << "B组" << "C组" << "D组";
    QBarCategoryAxis *axisX = new QBarCategoryAxis();
    axisX->append(categories);
    chart->addAxis(axisX, Qt::AlignBottom);
    series->attachAxis(axisX);

//    chart->createDefaultAxes();
    chart->legend()->setVisible(false);
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->setBackgroundVisible(false);
    chart->axisX()->setGridLineVisible(false);
    chart->axisX()->setLabelsColor(QColor(255,255,255));
    chart->axisX()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisX()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    QValueAxis *axisY = new QValueAxis();
    chart->addAxis(axisY, Qt::AlignLeft);
    series->attachAxis(axisY);
    chart->axisY()->setGridLineVisible(true);
    chart->axisY()->setGridLineColor(QColor(156, 82, 225,120));
    chart->axisY()->setTitleText("");
    chart->axisY()->setLabelsColor(QColor(255,255,255));
    chart->axisY()->setLabelsFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setVisible(true);
    chart->axisY()->setTitleBrush(QColor(255,255,255));//设置x轴字体颜色
    chart->axisY()->setTitleFont(QFont("微软雅黑", 12, QFont::Normal, false));
    chart->axisY()->setRange(0,100);
//    chart->setTitle("直方图");
//    chart->setTitleFont(QFont("微软雅黑", 14, QFont::Bold, false));
//    chart->setTitleBrush(QColor(255,255,255));
    chart->legend()->setVisible(true);
    chart->legend()->setAlignment(Qt::AlignBottom);
    chart->legend()->setLabelColor(QColor(255,255,255));
    chart->legend()->setFont(QFont("微软雅黑",12,true));
    return chart;
}

void CreatCharts::update_ABCDHistBarData(double data_a, double data_b, double data_c, double data_d)
{
    AHist_BarSet->replace(0,data_a);
    BHist_BarSet->replace(1,data_b);
    CHist_BarSet->replace(2,data_c);
    DHist_BarSet->replace(3,data_d);
}
